import { Controller, Get, Post, Body, Param, Delete, Query, Put } from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { NotifyService } from './notify.service';
import { CreateNotifyDto, ListNotifyDto, UpdateNotifyDto } from './dto/index';
import { RequirePermission } from 'src/common/decorators/require-premission.decorator';

@ApiTags('通知管理')
@Controller('notify')
export class NotifyController {
  constructor(private readonly notifyService: NotifyService) {}

  @ApiOperation({
    summary: '创建通知',
  })
  @RequirePermission('system:notify:add')
  @Post()
  create(@Body() createNotifyDto: CreateNotifyDto) {
    return this.notifyService.create(createNotifyDto);
  }

  @ApiOperation({
    summary: '通知列表',
  })
  @RequirePermission('system:notify:list')
  @Get('list')
  findAll(@Query() query: ListNotifyDto) {
    console.log('Received query:', query);
    return this.notifyService.findAll(query);
  }

  @ApiOperation({
    summary: '通知详情',
  })
  @RequirePermission('system:notify:query')
  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.notifyService.findOne(+id);
  }

  @ApiOperation({
    summary: '删除通知',
  })
  @RequirePermission('system:notify:remove')
  @Delete(':ids')
  remove(@Param('ids') ids: string) {
    const notifyIds = ids.split(',').map(id => +id);
    return this.notifyService.remove(notifyIds);
  }

  @Put()
  @RequirePermission('system:notify:edit')
  @ApiOperation({
    summary: '更新通知',
  })
  update(@Body() updateNotifyDto: UpdateNotifyDto) {
    return this.notifyService.update(updateNotifyDto);
  }
} 